/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DatabaseAccess;
import Entity.BRSCustomer;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
/**
 *
 * @author TienDung
 */
public class CustomerAccess {

    D_DBHelper db=null;
    public CustomerAccess(){
        db=new D_DBHelper();
        if(!db.setupConnection()){
            JOptionPane.showMessageDialog(null,"Can not open the connection","Connection Dialog",JOptionPane.ERROR_MESSAGE);
        }
        else{
           
        }
    }


    public BRSCustomer getCustomerByID(String ID) {
        BRSCustomer newCuts = null;
        Vector getUserListPara = new Vector();
        getUserListPara.add(ID);
        try {
            
            String sql = "spSearchCustomerByCode";
            ResultSet rs = db.executeProcedure(sql, getUserListPara);
            while (rs.next()) {
                newCuts = new BRSCustomer();
                newCuts.setCusID(rs.getInt(1));
                newCuts.setCusName(rs.getString(2));
                newCuts.setCusAddress(rs.getString(3));
                newCuts.setCusEmail(rs.getString(4));
                newCuts.setCusPhone(rs.getInt(5));
                return newCuts;
            }
        } catch (SQLException ex) {
            //Logger.getLogger(SupplierAccess.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        } catch (Exception ex) {
            //Logger.getLogger(UserAccess.class.getName()).log(Level.SEVERE, null, ex);
            ex.printStackTrace();
            return null;
        }
        return null;
    }
}
